/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.apt.citytag.process;

import com.apt.bean.Cities;
import com.apt.tag.Connect_DB;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;

/**
 *
 * @author Bach
 */
public class GetCity {

    public static HashMap<Integer, Cities> getListCity(String countrise_Id) {
        HashMap<Integer, Cities> listFB = new HashMap<Integer, Cities>();
        PreparedStatement ps = null;
        ResultSet rs = null;
        Connection conn = null;
        String query = "SELECT [City_Id]\n"
                + "      ,[Country_Id]\n"
                + "      ,[City_Name]\n"
                + "      ,[City_Status]\n"
                + "  FROM [Matrimony].[dbo].[Cities] "
                + " Where [Country_Id]=?";
        try {
            conn = Connect_DB.getConnection();
            if (conn != null) {
                ps = conn.prepareStatement(query);
                ps.setInt(1, Integer.parseInt(countrise_Id));
                rs = ps.executeQuery();
                int key = 1;

                String city_Id;
                String country_Id;
                String city_Name;
                String city_Status;

                while (rs.next()) {
                    country_Id = rs.getString("Country_Id");
                    city_Name = rs.getString("City_Name");
                    city_Status = rs.getString("City_Status");
                    city_Id = rs.getString("City_Id");
                    Cities fb = new Cities(city_Id, country_Id, city_Name, city_Status);
                    listFB.put(key, fb);
                    key++;
                }
            } else {
                System.out.println("Connect is null");
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            Connect_DB.close(rs, null, ps, conn);
        }
        return listFB;
    }
}
